package common;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.sun.org.apache.xerces.internal.util.SynchronizedSymbolTable;

public class MiddleCommonUtils {
	
	/**
	 * 正则判断
	 */
	public static boolean match(String str,String regex){
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		return matcher.find();
	}
	/**
	 * 正则取字符串
	 */
	public static String getMatch(String str,String regex){
		return getMatch(str,regex,null);
	}
	
	public static String getMatch(String str,String regex,Integer no){
		String retStr = null;
		Pattern pattern = Pattern.compile(regex);
		Matcher matcher = pattern.matcher(str);
		if(no != null && no >0){
			retStr = matcher.find()?matcher.group(no):"";
		}else{
			retStr = matcher.find()?matcher.group():"";
		}
		return retStr;
	}
	public static String getName(String title){
		return getMatch(title,"(- )([^\\[]*)\\[(\\d{5})",2);
	}
	
	public static String getId(String title){
		return getMatch(title,"(- )([^\\[]*)\\[(\\d{5}\\d+)\\]",3);
	}
	
	public static void main(String[] a){
//		String title = "梦幻西游 ONLINE - (笑傲三界[华山论剑] - 柯Ⅱ初丹ㄋ[681954])";
		String title = "梦幻西游 ONLINE - (追忆[2020] - PS老哥[16309108])";
		System.out.println(getName(title));
		System.out.println(getId(title));
	}
}
